package myJs.api

import myJs.Implicits._
import myJs.myPkg.MyFetch
import org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits._
import shared.Pojo._
import shared.tsPojo.TsPojo
import upickle.default._

/** Created by yz on 7/5/2022
  */
object Tool {

  import TsPojo.tool._

  val baseUrl = s"${Api.apiUrl}/gepLiver/tool"
  val pngImage = s"${baseUrl}/pngImage"
  val downloadFile = s"${baseUrl}/pathDownloadFile"

  def png2jpeg(request: Png2jpeg.Request) = {
    val url = s"${baseUrl}/png2jpeg"
    MyFetch
      .postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json"))
      .map { str =>
        read[Png2jpeg.Response](str)
      }
  }

  def png2pdf(request: Png2jpeg.Request) = {
    val url = s"${baseUrl}/png2pdf"
    MyFetch
      .postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json"))
      .map { str =>
        read[Png2jpeg.Response](str)
      }
  }

  def png2svg(request: Png2jpeg.Request) = {
    val url = s"${baseUrl}/png2svg"
    MyFetch
      .postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json"))
      .map { str =>
        read[Png2jpeg.Response](str)
      }
  }

}
